<link rel="stylesheet" href="{__SYSTEM_PATH__}/js/layui/css/dropdown.css">
<div class="row content-nav">
    <div class="col-xs-12">
        <ul>
            <li><a href="javascript:;"><i></i>&nbsp;任务管理</a></li>
            <li><a href="javascript:;">任务列表</a></li>
        </ul>
    </div>
</div>

<div class="layui-fluid" id="search-box">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">任务分类：</label>
                        <div class="layui-input-inline seller-inline-4" style="width:300px;">
                        <select name="type_id">
                            <option value="">全部</option>
                            {if !empty($type_list)}
                            {volist name="type_list" id="value"}
                            <option value="{$value.id}">{$value.level|raw}{$value.name|raw}</option>
                            {/volist}
                            {/if}
                        </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">任务状态：</label>
                        <div class="layui-input-inline seller-inline-4">
                            <select name="status">
                                <option value="-1">全部</option>
                                 {if !empty($status_list)}
                                  {volist name="status_list" id="item"}
                                    <option value="{$key}">{$item}</option>
                                  {/volist}
                                 {/if}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">发布用户：</label>
                        <div class="layui-input-inline seller-inline-4">
                            <input type="text" name="publisher" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label seller-inline-2">任务单号：</label>
                        <div class="layui-input-inline seller-inline-4">
                            <input type="text" name="job_no" placeholder="请输入任务单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
				    <div class="layui-inline">
				      <label class="layui-form-label">发布时间：</label>
				      <div class="layui-input-inline" style="width:300px;">
				        <input type="text" class="layui-input" id="publish_time" name="publish_time" placeholder=" - ">
				      </div>
				    </div>
                    <div class="layui-inline">
                      <label class="layui-form-label">过期时间：</label>
                      <div class="layui-input-inline" style="width:300px;">
                        <input type="text" class="layui-input" id="exp_time" name="exp_time" placeholder=" - ">
                      </div>
                    </div>
                    <div class="layui-inline">
                        <button type="button" id="search-btn" class="layui-btn layui-btn-sm layui-bg-light-blue"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<section class="content clearfix">
    <div class="layui-list-box">
        <table class="layui-hide" id="list-box" lay-filter="list-box"></table>
    </div>
</section>

<script type="text/html" id="list-toolbar">
    <div class="layui-btn-container">
<!--         <button lay-event="url" type="button" class="layui-btn layui-btn-sm layui-bg-light-blue"><i class="layui-icon">&#xe61f;</i> 添加</button> -->
        <button lay-event="refresh" type="button" class="layui-btn layui-btn-sm layui-bg-red"><i class="layui-icon">&#xe9aa;</i> 刷新</button>
    </div>
</script>

<script type="text/html" id="list-bar">
    <!-- ,{layIcon:'layui-icon-fire',txt: '秒杀', event:'second'},{layIcon:'layui-icon-diamond',txt: '积分', event:'point'}, {layIcon: 'layui-icon-edit',txt: '编辑', event:'edit'}, {layIcon: 'layui-icon-delete', txt: '删除', event:'del'} -->
<!--     <button class="layui-btn layui-btn-xs layui-btn-danger" lay-dropdown="{align:'right', menus: [{txt: '详情', event:'details'}]}">
        <span>操作</span>
        <i class="layui-icon layui-icon-triangle-d"></i>
    </button> -->
</script>

<script>
layui.config({
    base: "{__SYSTEM_PATH__}/js/layui/extend/"
}).use(['table','dropdown','form','laydate'], function () {
    var table = layui.table;
    var dropdown = layui.dropdown;
    var form = layui.form;
    var laydate = layui.laydate;
	laydate.render({
	    elem: '#publish_time'
	    ,type: 'datetime'
		,range: '~'
	});
    laydate.render({
        elem: '#exp_time'
        ,type: 'datetime'
        ,range: '~'
    });
    table.render({
        elem: '#list-box'
        , url: '{:createUrl("index")}'
        , toolbar: '#list-toolbar'
        , defaultToolbar: []
        , title: '数据表'
        , cols: [[
                  {type: 'checkbox'}
                , {field: 'name', title: '任务名', width: 150,align:"left"}
                , {field:"type_name",title:"分类",align:"center"}
                , {field:"accept_issue",title:"接单 / 总数",width:110,align:"center"}
                , {field:"finish_fail",title:"完成 : 失败",width:110,align:"center"}
                , {field:"accept_executing_num",title:"未结束",width:80,align:"center"}
                , {field:"price_total",title:"单价 / 总价",width:150,align:"center"}
                , {field:"requirement",title:"任务介绍",width:200,align:"left"}
                , {field:"publisher",title:"发布人",width:120,align:"center"}
                , {field:"publish_time_text",title:"发布时间",width:130,align:"center"}
                , {field:"exp_time_text",title:"过期时间",width:130,align:"center"}
                , {field:"status_name",title:"状态",align:"center"}
                , {fixed: 'right', align: 'center', title: '操作', width: 100,templet: function(res){
                    var str='';
                    str+='<button class="layui-btn layui-btn-xs" lay-dropdown="{align:\'right\',menus:[{txt: \'详情\', event:\'details\'}';
                    if(res.status==11){
                        str+=',{txt: \'审核\', event:\'audit\'}';
                    }
                    str+=']}"><span>操作</span><i class="layui-icon layui-icon-triangle-d"></i></button>';
                    console.log(str);
                    return str;
                }}
            ]]
        , done: function (res) {
            dropdown.suite();
            $("td[data-field=accept_executing_num]").each(function(){
                if($(this).find('div').html() != 0) {
                    $(this).css({'color':'red'});
                }
            });
            $("td[data-field=name]").click(function () {
            })
        }
        , page: true
        , id: 'list-table'
        , height: 'full-310'
        // ,limit:30
    });



    $("#search-btn").on("click",function (){
        //执行重载
        table.reload('list-table', {
          page: {
            curr: 1
          }
          ,where: {
            key: {
              type_id : $('[name="type_id"]').val(),
              status : $('[name="status"]').val(),
              publisher : $('[name="publisher"]').val(),
              job_no : $('[name="job_no"]').val(),
              publish_time : $('[name="publish_time"]').val(),
              exp_time : $('[name="exp_time"]').val()
            }
          }
        }, 'data');
    });

    //头工具栏事件
    table.on('toolbar(list-box)', function (obj) {
        switch (obj.event) {
            case 'url':
                window.location.href = "{:createUrl('editor')}";
                break;
            case 'refresh':
                window.location.reload();
                break;
        }
    });

    //监听行工具事件
    table.on('tool(list-box)', function (obj) {
        var data = obj.data;
        if(obj.event == 'details') {
            showDetails(data.id,data.name);
        } else if (obj.event === 'del') {
            layer.confirm('你确定要删除吗？', function (index) {
                $.get('{:createUrl("delete")}',{
                    id : data.id
                },function(result){
                    layer.close(index);
                    if(result.code){
                        obj.del();
                    }else{
                        layer.msg(result.msg,{ icon : 2 });
                    }
                },"json");
            });
        } else if (obj.event === 'edit') {
            window.location.href = '{:createUrl("editor")}?id='+data.id;
        }else if(obj.event == 'group'){
            window.location.href = '{:createUrl("editor_group")}?id='+data.id;
        }else if(obj.event == 'regiment'){
            window.location.href = '{:createUrl("editor_regiment")}?id='+data.id;
        }else if(obj.event == 'second'){
            window.location.href = '{:createUrl("editor_second")}?id='+data.id;
        }else if(obj.event == 'point'){
            window.location.href = '{:createUrl("editor_point")}?id='+data.id;
        }else if(obj.event == 'audit'){
                layer.open({
                    type: 2,
                    title: '审核',
                    shadeClose: true,
                    shade: 0.3,
                    area: ['25%', '48%'],
                    content: '{:createUrl("audit")}?id='+data.id
                });
            }
    });

    //监听单元格编辑
    table.on('edit(list-box)', function(obj){
        $.get('{:createUrl("field")}',{
            name : obj.field,
            value : obj.value,
            id : obj.data.id
        },function (result){
            if(!result.code){
                layer.msg(result.msg,{ icon : 2 });
            }
        },"json");
    });


    /**
     * 显示详情
     * @param id
     * @param title
     */
    function showDetails(id,title) {
        layer.open({
            type: 2,
            title: title,
            shadeClose: true,
            shade: 0.3,
            area: ['80%', '90%'],
            content: '{:createUrl("details")}?id='+id
        });
    }

});
</script>





